package com.cyq.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.LocaleResolver;
import org.springframework.web.servlet.config.annotation.ViewControllerRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

@Configuration
public class MyMvcConfig implements WebMvcConfigurer {

    /*指定那些路径会跳转到index页面*/
    @Override
    public void addViewControllers(ViewControllerRegistry registry) {
        registry.addViewController("/").setViewName("index");
        registry.addViewController("/index.html").setViewName("index");
        registry.addViewController("/main.html").setViewName("dashboard");
        registry.addViewController("/user.html").setViewName("user/UserAdd");
        registry.addViewController("/test.html").setViewName("user/test");
        registry.addViewController("/pwd.html").setViewName("user/PassWord");
        registry.addViewController("/toUnauthorizedByMe").setViewName("error/404");
    }

    /*将自定义的国际化解析器注入到bean中*/
    @Bean
    public LocaleResolver localeResolver(){
        return new MyLocaleResolver();
    }
    @Bean
    public throw403 diyExceptionHandler() {
        return new throw403();
    }

    /*将自定义的登录拦截器LoginHandlerInterceptor注入到interceptor中*/
    /*@Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new LoginHandlerInterceptor())
                .addPathPatterns("/**")
                .excludePathPatterns("/index.html","/","/user/login","/css/*","/js/*","/img/*");
                *//*.excludePathPatterns("/index.html","/","/user/login","/static/*");*//*

    }*/
}
